package cn.dylan.xhr;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class XhrProducer1 {
    public static void main(String[] args) throws Exception {
        // 创建对象
        DefaultMQProducer producer = new DefaultMQProducer("xhr_producer_group1");
        // 连接mq
        producer.setNamesrvAddr("localhost:9876");

        // 开启
        producer.start();
        //新建信息，并发送
        Message message = new Message("xhr", "hello", "这个三三就是逊".getBytes(StandardCharsets.UTF_8));
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("生产者发送消息成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("生产者发送消息失败");
            }
        });
        System.out.println("出来了");
    }
}
